package cn.yikaojiuguo.student.ui.ask;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.yikaojiuguo.student.R;
import cn.yikaojiuguo.student.app.YiKaoApplication;
import cn.yikaojiuguo.student.bean.Category;
import cn.yikaojiuguo.student.support.database.MyDBManager;
import cn.yikaojiuguo.student.support.simple.ArgsConstants;
import cn.yikaojiuguo.student.ui.base.CustomerActionBarActivity;

public class AskChooseMajorActivity extends CustomerActionBarActivity {

    @Bind(R.id.lv)
    ListView mLv;
    private List<Category> mList;
    private ArrayAdapter mAdapter;

    public static Intent newIntent() {
        Intent intent = new Intent(YiKaoApplication.getInstance(),AskChooseMajorActivity.class);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ask_choose_major);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mList = MyDBManager.queryByEvalue(ArgsConstants.EVALUE_MAJOR);
        mAdapter = new ArrayAdapter<Category>(this, android.R.layout.simple_list_item_1,
                mList);
        mLv.setAdapter(mAdapter);
        mLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String majorId = mList.get(position).id + "";
                Intent data = new Intent();
                data.putExtra(ArgsConstants.MAJOR_ID,majorId);
                setResult(Activity.RESULT_OK, data);
                finish();
            }
        });
    }
}
